<?php

/**
 * @author chenshubo
 * 查询订单物流单号
 */
namespace App\Service\OrderService\OrderInterfaceService;

use App\Service\Code\Normal;
use App\Service\BaseService;
use App\Model\PssModel\OrderSupplier;

class OrderExpress extends BaseService
{   
    /**
     * 查询订单物流单号
     */
    public function index( $param = [] )
    {
        $bid = $param['binfo']['bid'];
        $requestData = $param['requestData'];
        if( empty($requestData['orderSn']) ) {
            return Normal::returnCode(Normal::FAIL,"orderSn订单号不能为空");
        }
        
        //根据原始订单号查询商户的
        $orderSn = checkFields($requestData['orderSn']);
        if( $orderSn != $requestData['orderSn'] ) {
            return Normal::returnCode(Normal::FAIL,"orderSn订单号不能包含特殊字符");
        }
        
        //查询订单
        $orderInfo  = OrderSupplier::instance()->getUserSupplierOrderExpressByBidAndOrderSn($bid,$orderSn);
        
        //未发货
        if( empty($orderInfo) ) {
            return Normal::returnCode(Normal::FAIL,"未发货");
        }
        
        $orderInfo = array_map(function( & $value ){
            $value['deliveryTime'] = !empty($value['deliveryTime']) ? date("Y-m-d H:i:s",$value['deliveryTime']) : '';
            return $value;
        },$orderInfo);
        
        //已发货
        return Normal::returnCode(Normal::SUC,"查询物流成功",[
            'expressInfo' => $orderInfo
        ]);
    }
}